home *** CD-ROM | disk | FTP | other *** search
- Path: ix.netcom.com!netnews
- From: miker3@ix.netcom.com (Mike Rubenstein)
- Newsgroups: comp.lang.c
- Subject: Re: Newbie question: Is this code OK?
- Date: Fri, 19 Jan 1996 22:11:28 GMT
- Organization: Netcom
- Message-ID: <31000875.75333568@nntp.ix.netcom.com>
- References: <4dmebk$foq@pegasus.interpac.net> <4doajv$ov0$2@mhafn.production.compuserve.com>
- NNTP-Posting-Host: ix-dc6-09.ix.netcom.com
- X-NETCOM-Date: Fri Jan 19 2:11:27 PM PST 1996
- X-Newsreader: Forte Agent .99c/16.141
-
- Bill Symmes <71046.623@CompuServe.COM> wrote:
-
- > Why not just
- >
- > while (*string)
- > if (isspace(*string++)
- > numwords++;
-
- How many words in this sentence?
-
- Also, there's another problem in your code and others. Assuming
- string is a pointer to char or array of char, isspace(*string++) may
- be invalid. isspace() requires an int argument that is equal to a
- value valid for an unsigned char or to EOF. If char is signed,
- *string may be a negative value that is invalid for isspace(). The
- test for space should be isspace((unsigned char) *string++).
-
-
- Michael M Rubenstein
-